<template>
<div>
  <div class="loader-base" v-if="showLoad"><div class="loader-wrap"></div></div>
  <header class="hd-top">
    <span class="iconfont icon-left" @click="goBack"></span>
    <h2 class="title">设置</h2>
  </header>
  <ul class="main-list">
    <li class="displayflex">
      <popup-picker class="picker-wrap" 
            title="字体大小" 
            :data="classfiyList" 
            placeholder="点击选择" 
            value-text-align="right"
            :show-name="classfiyshow"
            v-model="classfiy"></popup-picker>
      <i class="iconfont icon-right"></i>
    </li>
    <li class="displayflex" @click="clear"><span class="flex1">清除缓存</span></li>
    <li class="displayflex"><span class="flex1">版本</span><em>v1.0.0.0</em></li>
  </ul>
</div>
</template>

<script>
export default{
  data(){
    return{
      showLoad:false,
      //商品类型
      classfiyshow: true,
      classfiy: [],
      classfiyList: [
        [
          {
            value: "24",
            name: "大"
          },
          {
            value: "16",
            name: "中（默认）"
          },
          {
            value: "14",
            name: "小"
          }
        ]
      ],
    }
  },
  created(){
    if(localStorage.ft){
      this.classfiy.push(localStorage.ft);
    }else{
      this.classfiy.push('16');
    };
  },
  watch:{
    classfiy(newv){
      document.body.style.fontSize = newv+'px';
      if(newv=='24'){
        document.body.setAttribute("class","font-big");
        localStorage.ftClass = "font-big"; 
      }else if(newv=='14'){
        document.body.setAttribute("class","font-sm");
        localStorage.ftClass = "font-sm"; 
      }else{
        document.body.removeAttribute("class");
        localStorage.removeItem('ftClass');
      };
      localStorage.ft = newv; 
    }
  },
  methods:{
    goBack(){
      this.$router.go(-1)
    },
    clear(){
      this.showLoad = true;
      var _this = this,
          userinfo = JSON.parse(localStorage.UserInfo),
          query = {
            LogonUser:userinfo.LogonUser,
            Pwd:userinfo.Pwd,
            reLogin: 'Y',
          };
      //清除
      sessionStorage.clear();
      localStorage.clear();
      //重加载
      this.Ajax.post('UserLogin', query).then(function(resp) {
        if (resp.IsSuccess) {
            localStorage.UserInfo = JSON.stringify(resp.Data);
        } else {
          _this.$vux.toast.show({
            type:'warn',//success, warn, cancel, text
            text: "缓存操作失败，请重新登录",
            onHide(){
              _this.$router.push({
                path:'/login'
              });
            }
          });
        };
        _this.showLoad = false;
      });
    }
  }
}
</script>